﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>扩展控件</title>
    <script type="text/javascript" src="../../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../../Comm/Gener.js"></script>
    <script src="DDLBar.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        //页面启动函数.
        $(function () {

            InitBar("6");

            var html = "";
            var keyOfEn = GetQueryString("KeyOfEn");
            var fk_mapData = GetQueryString("FK_MapData");
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddPara("SQLKey", "EditFExtContral_AthList");
            handler.AddPara("Paras", "@FK_MapData=" + fk_mapData);
            var data = handler.DoMethodReturnString("SQLList");
            if (data.indexOf('err@') == 0) {
                alert(data);
            }

            data = JSON.parse(data);

            var mapAttr = new Entity("BP.Sys.MapAttr", fk_mapData + "_" + keyOfEn);
            // 绑定附件列表"
            GenerBindDDL("DDL_Ath", data, "NO", "NAME");
            $("#DDL_Ath").val(mapAttr.GetPara("AthRefObj")); //设置选择的值.
            $("#DDL_AthShowModel").val(mapAttr.GetPara("AthShowModel")); //设置选择的值.
        });
        function Save() {
            var DDL_Ath = $("#DDL_Ath").val();
            if (DDL_Ath == null) {
                alert("该表单中没有附件，请您先在表单设计器中创建一个附件");
                return;
            }
            //处理附件的保存业务逻辑相对复杂. 把这部分业务逻辑使用js实现, 并把里面的.cs的代码删除掉.
            var frmID = GetQueryString("FK_MapData");
            var keyOfEn = GetQueryString("KeyOfEn");
            var mapAttrAth = new Entity("BP.Sys.MapAttr", frmID + "_" + keyOfEn);
            mapAttrAth.UIContralType = '6';
            mapAttrAth.SetPara("AthRefObj", $("#DDL_Ath").val());
            mapAttrAth.SetPara("AthShowModel", $("#DDL_AthShowModel").val());
            mapAttrAth.Update();

            //把该附件组件隐藏掉.
            var ath = new Entity("BP.Sys.FrmAttachment", $("#DDL_Ath").val());
            ath.IsVisable = 0;
            ath.Update();

            //删除该附件组件的分组.
            var group = new Entity("BP.Sys.GroupField");
            group.Delete("FrmID", GetQueryString("FK_MapData"), "CtrlID", $("#DDL_Ath").val());
            alert('保存成功');
            window.location.href = window.location.href;
        }
       

    </script>
    
</head>
<body>
    <div id="bar">
    </div>
    <fieldset>
         <ul>
            <li>请选择一个附件
                <select id="DDL_Ath" name="DDL_Ath">
                </select>该附件的上传的文件数据就显示到这个控件上.</li>
            <li><a href="javascript:EditAth()">编辑附件</a></li>
            <script type="text/javascript">
                function EditAth() {
                    //增加附件判断
                    var DDL_Ath = $("#DDL_Ath").val();
                    if (null == DDL_Ath) {
                        alert("该表单中没有附件，请您先在表单设计器中创建一个附件");
                        return;
                    }
                    var ddl = document.getElementById("DDL_Ath");
                    var mypk = ddl.options[ddl.selectedIndex].value;
                    var url = '../../../Comm/En.htm?EnName=BP.Sys.FrmUI.FrmAttachmentExt&MyPK=' + mypk;
                    WinOpen(url);
                }
            </script>
            <li>文件数据展示模式:
                <select id="DDL_AthShowModel" name="DDL_AthShowModel">
                    <option value="0">简洁模式. 格式: 附件(x) </option>
                    <option value="1">仅文件名称. 格式: 我的文件1.doc,我的文件2.doc </option>
                </select>
                .</li>
        </ul>
    </fieldset>
</body>
</html>
